import axios, {ResDataType, ResType} from "./ajax";

type SearchOption = {
    keyword: string,
    isStar: boolean,
    isDeleted: boolean,
    pageSize: number,
    page: number

}

export async function getQuestionsService(id: string): Promise<ResDataType> {
    const url = `/api/questions/${id}`;
    const res = await axios.get(url);
    const data = (await axios.get(url)) as ResDataType;
    return data as ResDataType;
}

//创建问卷
export async function createQuestionService(): Promise<ResDataType> {
    const url = '/api/questions';
    const data = (await axios.post(url)) as ResDataType;
    return data;
}

//获取问卷列表
export async function getQuestionListService(opt: Partial<SearchOption> = {}): Promise<ResDataType> {
    const url = '/api/questions';
    const data = (await axios.get(url, {params: opt})) as ResDataType;
    return data;
}

//修改
export async function updateQuestionService(id: string, opt: { [key: string]: any }): Promise<ResDataType> {
    const url = `/api/questions/${id}`;
    const res = await axios.patch(url, opt);
    return res as ResDataType;
}

//复制
export async function duplicateQuestionService(id: string): Promise<ResDataType> {
    const url = `/api/questions/duplicate/${id}`;
    const res = await axios.post(url);
    return res as ResDataType;
}

//彻底删除
export async function deleteQuestionService(ids: string[]): Promise<ResDataType> {
    const url = `/api/questions/`;
    const res = await axios.delete(url, {data: {ids}});
    return res as ResDataType;

}